****APPENDIX TABLE C2****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

fegen ccode_survey_year = group(ccode survey_year)
fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)
fegen ccode_yob = group(ccode yob) if yob!=-99

cap drop sample gallup_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
gen gallup_sample = 1 if born_country==1 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup"
replace gallup_sample = 1 if total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

//--------------------------------------------------------
//Create Table C2 (Panel A)
//--------------------------------------------------------

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)	
standardize trust_govt

//Column 1
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode_yob)
outreg2 using table_c2_panel_a.doc, replace dec(3) nocons addtext(Cluster Level, Country x Cohort) keep(zwgrowth_rate_1) 

//Column 2														  
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode yob)
outreg2 using table_c2_panel_a.doc, append dec(3) nocons addtext(Cluster Level, Country-Cohort) keep(zwgrowth_rate_1) 

//Column 3														 
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode survey_year)
outreg2 using table_c2_panel_a.doc, append dec(3) nocons addtext(Cluster Level, Country-Survey Year) keep(zwgrowth_rate_1) 

//Column 4														 
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode_survey_year)
outreg2 using table_c2_panel_a.doc, append dec(3) nocons addtext(Cluster Level, Country x Survey Year) keep(zwgrowth_rate_1) 

//Column 5														 
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode_yob survey_year)
outreg2 using table_c2_panel_a.doc, append dec(3) nocons addtext(Cluster Level, Country x Cohort & Survey Year) keep(zwgrowth_rate_1) 
														 
//--------------------------------------------------------
//Create Table C2 (Panel B)
//--------------------------------------------------------

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)	
standardize trust_govt

//Column 1
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode_yob)
outreg2 using table_c2_panel_b.doc, replace dec(3) nocons addtext(Cluster Level, Country x Cohort) keep(zwgrowth_rate_1) 

//Column 2														  
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode yob)
outreg2 using table_c2_panel_b.doc, append dec(3) nocons addtext(Cluster Level, Country-Cohort) keep(zwgrowth_rate_1) 

//Column 3														 
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode survey_year)
outreg2 using table_c2_panel_b.doc, append dec(3) nocons addtext(Cluster Level, Country-Survey Year) keep(zwgrowth_rate_1) 

//Column 4														 
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode_survey_year)
outreg2 using table_c2_panel_b.doc, append dec(3) nocons addtext(Cluster Level, Country x Survey Year) keep(zwgrowth_rate_1) 

//Column 5														 
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode_yob survey_year)
outreg2 using table_c2_panel_b.doc, append dec(3) nocons addtext(Cluster Level, Country x Cohort & Survey Year) keep(zwgrowth_rate_1) 
